package com.wzw.tcxb;

import java.util.Iterator;
import java.util.List;

import org.dom4j.Element;

import com.wzw.tcjh.Customer;
import com.wzw.tcjh.CustomerTools;
import com.wzw.tcjh.StrUtils;
import com.wzw.util.UpdateXML;
import com.wzw.util.XMLUtil;

public class UpdateAwardCustomerXml implements UpdateXML {

	@Override
	public void updateAwardCustomer(List<Customer> list, String webroot) {
		XMLUtil xml = new XMLUtil("menu");
		xml.setOutFile(webroot + "tcxb/data.xml");
		Iterator<Customer> iterator = list.iterator();
		while(iterator.hasNext()) {
			Customer customer = iterator.next();
			Element e = xml.addElements("item");
			e.addAttribute("type", "news");
			(e.addElement("hjname")).setText(customer.getName());
			(e.addElement("hjtel")).setText(customer.getPhone());
			(e.addElement("hjdate")).setText(customer.getDate());
		}
		xml.writeToXMLFile();
	}
	
	public static String getAward(String pcode) {
		List<Customer> customerList = CustomerTools.getCustomerList("and isreward = 1 and projectcode = '" + pcode + "'", null);
		XMLUtil xml = new XMLUtil("menu");
		Iterator<Customer> iterator = customerList.iterator();
		while(iterator.hasNext()) {
			Customer customer = iterator.next();
			Element e = xml.addElements("item");
			e.addAttribute("type", "news");
			(e.addElement("hjname")).setText(customer.getName());
			(e.addElement("hjtel")).setText(StrUtils.convertPhone(customer.getPhone(), 3, 7));
			(e.addElement("hjdate")).setText(customer.getDate());
		}
		return xml.docToString();
		
	}

}
